<!DOCTYPE html>
<html>
  <head>
     <meta charset="UTF-8">
    <title>post page</title>
    <link rel='stylesheet' href='/stylesheets/style.css' />
    <link rel="stylesheet" href="/editormd/css/editormd.min.css" />
  </head>
  <body>
    <div class="container">
      <h1>write artitle</h1>
      <form id="modify-form">
          <div>
            <span>title</span>
            <input id="article-title" type="input" name="title" value="<%=article.title %>"/>
          </div>
          <div>
            <span>content</span>
            <div id="editormd">
              <textarea id="article-content" style="display:none;" name="content"><%=article.content %></textarea>
            </div>
          </div>
          <div>
              <input type="submit" value="submit"/>
          </div>
      </form>
    </div>
    <script type="text/javascript" src="/javascripts/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="/editormd/editormd.min.js"></script>
    <script type="text/javascript">
        $(function() {
          var editor = editormd({
              id:"editormd",
              path : "/editormd/lib/",
              height:500
          });

          $("#modify-form").submit(function(){
              $.ajax({
                  url:"/articles/<%=article.id %>",
                  type:"PUT",
                  data:{
                    title:$("#article-title").val(),
                    content:$("#article-content").text()
                  },
                  success:function(data){
                    if(data.code===1){
                        location.href="/";
                    }else{
                        alert(data.msg);
                    }
                  }
              });
              return false;
          });
        });
    </script>
  </body>
</html>
